<template>
  <div>
    <GQuerySearch placeholder="请输入姓名" @setValue="setQuery" />
    <GTable
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      usePager
      :pager="frontPager"
      :data="tableData"
      stripe
      border
      :columns="columns"
      :conf="tableConf"
    >
      <template #birthday="{ row }">
        <span>{{ row.birthday | birthday }}</span>
      </template>
      <template #operation="{ row }">
        <el-button type="primary" @click="showEditForm(row)">查看</el-button>
        <el-button type="success" @click="submit(row.id)">通过</el-button>
        <el-button type="danger" @click="rejectLoan(row.id)">拒绝</el-button>
      </template>
    </GTable>

    <el-dialog
      :visible.sync="showEdit"
      @open="innerShow = true"
      @closed="innerShow = false"
      width="30%"
      center
      :before-close="doClose"
    >
      <p slot="title">初审审批-查看详情</p>
      <GFormCreator ref="form1" v-if="innerShow" :config="editForm">
        <span slot="btn"></span>
      </GFormCreator>
      <span slot="footer" class="dialog-footer">
        <el-button @click="showEdit = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { columns, tableConf, genEditForm } from './pageConf'
import pager from '@/mixins/pager'
import crud from '@/mixins/crud'
import { passLoan, rejectLoan } from '@/api/loan'

export default {
  name:'first-approve',
  beforeDestroy(){
    console.log(this.$options.name+"被销毁了")
  },
  mixins: [pager, crud],
  methods: {
    doClose() {
      this.showEdit = false
    },
    beforeInit() {
      this.loadUrl = '/approve/first/list'
      return true
    },
    async submit(id) {
      let isSubmit = await this.$gConfirm('是否确定通过?')
      if (!isSubmit) return
      await passLoan(id, id)
      this.$message.success('提交成功')
      this.load()
    },
    async rejectLoan(id) {
      let isReject = await this.$gConfirm('是否确定拒绝?')
      if (!isReject) return
      await rejectLoan(id)
      this.$message.success('拒绝成功')
      this.load()
    },
    showEditForm(row) {
      this.editForm = Object.freeze(genEditForm(row))
      this.showEdit = true
    },
  },
  created() {
    // 测试代码
    this.load()
  },
  data() {
    return {
      tableConf,
      columns,
      showEdit: false,
      editForm: null,
      innerShow: false,
    }
  },
}
</script>
